package com.kai.admin.controller;

import com.kai.admin.data.response.CaptchaResponse;
import com.kai.admin.enums.CaptchaEnum;
import com.kai.admin.security.service.CaptchaService;
import com.kai.common.data.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 验证码
 *
 * @author weijk
 * @since 2023/7/21
 */
@RestController
@RequestMapping("/captcha")
@Tag(name = "验证码")
public class CaptchaController {

    @Autowired
    private CaptchaService captchaService;

    /**
     * 生成验证码
     *
     * @param captchaType 验证码类型
     * @return 验证码
     */
    @GetMapping("/generate")
    @Operation(summary = "生成验证码", parameters = {@Parameter(name = "captchaType", description = "验证码类型")})
    public Result<CaptchaResponse> generateCaptcha(@RequestParam(value = "captchaType", required = false, defaultValue = "SPEC") CaptchaEnum captchaType) {
        return Result.success(captchaService.generateCaptcha(captchaType));
    }
}
